Skip to content

fix(proactive): persist care messages to thread history and track replies - #3133

Merged
Bosheng0422 merged 1 commit into
developfrom
fix/3064-proactive-care-history
Nov 24, 2026
Merged

Bosheng0422 merged 1 commit into
developfrom
fix/3064-proactive-care-history

Conversation

@Bosheng0422

Copy link
Copy Markdown
Collaborator

Summary

Fixes #3064 — proactive care messages pushed to Dashboard (and IM) sessions were previously delivered through transport-only Gateway.push_text_from_session, so nothing was persisted to LangGraph checkpoints or thread_messages, leaving unread badges pointing at empty conversations and agents blind to what they just asked.

Phase 1: Persistence & non-disruptive delivery

  • Persist care messages as a single AIMessage: ProactiveCareService._deliver() runs under gateway.run_in_session(...), re-validates can_send() inside the session lock, binds the session's latest active thread (skipping empty placeholder threads, matching cron's default strategy), appends AIMessage(id="care:<ulid>:assistant") to both harness.aappend_messages(...) and thread_message_repo.append_if_ready(...), then pushes via push_session_text + best-effort notify_dashboard_push. Gateway.push_text_from_session remains transport-only.
  • Fix target session selection (select_care_target_session): strictly selects IM DM (is_im_session & chat_type == "dm") or falls back to Dashboard DM, preventing private emotional care from targeting MCP sessions (channel_id="octop-agent-mcp"), IM group chats, peer/team rooms, or CLI sessions.
  • Accurate human-only idle clock: adds ThreadMessageRepo.latest_human_activity(agent_id) (excluding synthetic cron:% prompts and AI messages), removing the 5-minute push-activity slack bug where a quick user reply within 5 minutes was ignored as our own push. Falls back to thread_repo.latest_user_activity for unprojected legacy threads.
  • HITL deferral: adds HitlPendingStore.has_pending_for_agent(agent_id) so proactive care defers while an approval prompt is pending.

Phase 2: Reply tracking & backoff

  • Schema extension: idempotently adds thread_id, message_id, care_text, status (sent / replied / ignored), replied_at, and reply_message_id plus indexes to care_push_records (SQLite + PostgreSQL).
  • Reply capture: GlobalProcessor._mark_care_replied marks the latest open care push on the thread as replied (and older open pushes on that thread as ignored) on genuine IM and Dashboard/CLI user turns (ignoring slash commands and HITL answers).
  • Unanswered backoff: ProactiveCareScheduler scales the push interval via backoff_interval_hours (1x for 0–1 unanswered, 2x for 2, 4x for 3+, capped at 7 days) and resets automatically once the user replies.

Target branch

  • Base is develop (feature / fix — default)
  • Base is main (release/* or hotfix/* only)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactor / chore
  • Release / hotfix

Test plan

  • Added/updated unit & integration tests (tests/unit/proactive/test_proactive_service.py, test_scheduler.py, test_care_reply_tracking.py)
  • pytest tests/unit/proactive tests/unit/gateway/test_gateway_push.py tests/unit/db/test_db_pool.py — 104 passed
  • pytest tests/unit/db/test_runtime_replace_services.py tests/unit/gateway/test_gateway.py tests/unit/gateway/test_hitl_channel.py tests/unit/gateway/test_dashboard_ws.py — 69 passed
  • ruff check src tests, ruff format --check src tests, mypy src/octop

Checklist

  • Updated CHANGELOG.md (if user-facing)
  • README / docs updated (if needed)

@Bosheng0422
Bosheng0422 merged commit a4a8dd4 into develop Nov 24, 2026
6 checks passed
@Bosheng0422
Bosheng0422 deleted the fix/3064-proactive-care-history branch November 24, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant